// 管理员: 系统管理(账户管理,角色管理,模块管理)  相关的接口

import service from '@/utils/request'
import constant from '@/utils/constant'
import Qs from 'qs'

const root = (process.env.NODE_ENV === 'development' ? '/api' : '')

// 删除管理员 delete========================================================================账户
export function delAdmin(ids) {
  return request({
    url: root + constant.del_admin,
    method: 'delete',
    data: ids
  })
}
// 添加管理员 post
export function addAdmin(password, roleId, status, userName) {
  return request({
    url: root + constant.add_admin,
    method: 'post',
    data: { password, roleId, status, userName }
  })
}
// 修改管理员数据 put
export function editAdmin(id, password, roleId, status, userName) {
  return request({
    url: root + constant.edit_admin,
    method: 'put',
    data: { id, password, roleId, status, userName }
  })
}
// 查管理列表
export function listAdmin(page, row, keyword) {
  return request({
    url: root + constant.list_admin,
    method: 'get',
    params: { page, row, keyword }
  })
}
// toggle管理员的 禁用/启用
export function toggleAdmin(adminId, status) {
  return request({
    url: root + constant.toggle_admin,
    method: 'put',
    data: Qs.stringify({ adminId, status })
  })
}

// 删除角色 delete====================================================================角色
export function delRole(ids) {
  return request({
    url: root + constant.del_role,
    method: 'delete',
    data: ids
  })
}
// 添加角色 post
export function addRole(permIds, remark, roleName) {
  return request({
    url: root + constant.add_role,
    method: 'post',
    data: { permIds, remark, roleName }
  })
}
// 修改角色 put
export function editRole(roleId, status, permList) {
  return request({
    url: root + constant.edit_role,
    method: 'put',
    params: { roleId, status, permList }
  })
}
// 获取角色列表  get
export function listRole(page, row, keyword) {
  return request({
    url: root + constant.list_role,
    method: 'get',
    params: { page, row, keyword }
  })
}
// 通过角色Id获取 该角色权限列表  get
export function permRole(roleId) {
  return request({
    url: root + constant.perm_role,
    method: 'get',
    params: { roleId }
  })
}

// 删除模块======================================================================模块管理
export function delModule(ids) {
  return request({
    url: root + constant.del_module,
    method: 'delete',
    data: ids
  })
}
// 添加模块
export function addModule(data) {
  return request({
    url: root + constant.add_module,
    method: 'post',
    data: data
  })
}
// 修改模块
export function editModule(app) {
  return request({
    url: root + constant.edit_module,
    method: 'put',
    data: app
  })
}
// 获取所有模块列表
export function listModule(app) {
  return request({
    url: root + constant.list_module,
    method: 'get',
    data: app
  })
}
